//
//  MenusResultVC.m
//  Menu
//
//  Created by mc on 16/4/22.
//  Copyright © 2016年 xmj. All rights reserved.
//

#import "MenusResultVC.h"
//#import "AFNetworking.h"
#import "MJExtension.h"
//#import "MBProgressHUD.h"
#import "Menus.h"
#import "MenusCell.h"


@interface MenusResultVC ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (strong, nonatomic) NSMutableArray *menus;
@property (assign, nonatomic) NSInteger page;

@end

@implementation MenusResultVC

static NSString * const REQUESTURL = @"http://apis.haoservice.com/lifeservice/cook/query?";


- (UITableView*)tableView

{
    if(_tableView==nil) {
        _tableView= [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
    }
    return _tableView;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //self.page = self.pagenum;
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    [self loadData];
}

- (void)loadData{
        // 利用MJExtension框架进行字典转模型
        self.menus = [Menus mj_objectArrayWithKeyValuesArray:self.dict];
        // 刷新数据（若不刷新数据会显示不出）
        [self.tableView reloadData];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return self.menus.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 1;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MenusCell *cell = [MenusCell menusCellWithTableView:self.tableView];
    cell.menus = self.menus[indexPath.section];
    [cell layoutIfNeeded];
    return cell;
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    Menus *menus = self.menus[indexPath.section];;
    return [MenusCell height:menus];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    // 跳转到详情.
    //    SelectCoursesDetailVC * detailVC = [[SelectCoursesDetailVC alloc] init];
    //    detailVC.selectCourse = self.selectCourses[indexPath.row];
    //    self.hidesBottomBarWhenPushed=YES;
    //    [self.navigationItem setBackBarButtonItem:[[UIBarButtonItem alloc]initWithTitle:@"" style:UIBarButtonItemStylePlain target:nil action:nil]];
    //
    //    [self.navigationController pushViewController: detailVC animated: YES];
    //    self.hidesBottomBarWhenPushed=NO;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 10;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}


@end
